package com.example.demo.day0306;

public class DemoInterrupt1 extends Thread {
    @Override
    public void run() {
        //加对线程是否中断进行判断
        if (Thread.currentThread().isInterrupted()) {//测试当前线程是否已经中断，但是不能清除状态标识
            System.out.println("线程"+Thread.currentThread().getName()+"已被中断！！");
            return;
        }
        System.out.println("线程"+Thread.currentThread().getName()+"在运行~~~~");

    }


    public static void main(String[] args) {

        //创建10条线程
        for (int i = 0; i < 10; i++) {
            Thread thread=new DemoInterrupt1();
            thread.start();
            //如果是偶数，那么就中断
            if (i%2==0) {
                thread.interrupt();
            }
        }

    }

}
